/**
 * [7] 整数反转
 *
 * @format
 * @lc app=leetcode.cn id=7 lang=javascript
 */

// @lc code=start
/**
 * @param {number} x
 * @return {number}
 */
var reverse = function (x) {
    const [min, max] = [-(2 ** 31), 2 ** 31 - 1]
    let num = 0
    while (x !== 0) {
        if ((min - (x % 10)) / 10 < num && (max - (x % 10)) / 10 > num) {
            num = num * 10 + (x % 10)
            x = parseInt(x / 10)
        } else {
            num = 0
            break
        }
    }
    return num
}

var reverse = function (x) {
    const [min, max, sign] = [-(2 ** 31), 2 ** 31 - 1, x > 0 ? 1 : -1]
    let num = sign * parseInt(x.toString().split("").reverse().join(""))
    num < min || num > max ? (num = 0) : null
    return num
}
// @lc code=end
